﻿@using System.Xml
@{
    XmlDocument doc = Checklist.GetXmlDocument(Request);
    Page.BonusPoints = doc.SelectNodes("//rule[@optional]").Count;
}

@foreach (XmlNode node in doc.SelectNodes("//category"))
{
    <section>
        <h2>@node.Attributes["name"].InnerText</h2>

        <ul>
            @foreach (XmlNode item in node.SelectNodes("rule"))
            {
                HtmlString className = new HtmlString(item.Attributes["optional"] != null ? " class=\"optional\"" : null);
                string name = item.Attributes["name"].InnerText;
                string id = name.Replace(" ", string.Empty).ToLowerInvariant();
                
                <li@className>
                    <input type="checkbox" id="@id" tabindex="1" />
                    <label for="@id">@name</label>

                    @{XmlNodeList links = item.SelectNodes("link");}

                    @if (links.Count > 0)
                    {
                        <em id="details-@id">◄</em>
                        <ul>
                            @foreach (XmlNode link in links)
                            {   
                                <li>
                                    <a href="@link.Attributes["url"].InnerText">@link.InnerText</a>
                                </li>                     
                            }
                        </ul>
                    }
                </li>  
            }
        </ul>
    </section>
}

<p id="bonus">Optional: <mark aria-relevant="text" aria-live="polite">0</mark>/@Page.BonusPoints</p>